package com.city.java.base.config;

import com.city.java.orders.pojo.entity.Orders;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 订单支付状态枚举处理器
 */
public class PaymentStatusHandler extends BaseTypeHandler<Orders.PaymentStatus> {

    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, Orders.PaymentStatus parameter, JdbcType jdbcType) throws SQLException {
        ps.setString(i, parameter.getValue());
    }

    @Override
    public Orders.PaymentStatus getNullableResult(ResultSet rs, String columnName) throws SQLException {
        String value = rs.getString(columnName);
        return value == null ? null : Orders.PaymentStatus.fromValue(value);
    }

    @Override
    public Orders.PaymentStatus getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        String value = rs.getString(columnIndex);
        return value == null ? null : Orders.PaymentStatus.fromValue(value);
    }

    @Override
    public Orders.PaymentStatus getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        String value = cs.getString(columnIndex);
        return value == null ? null : Orders.PaymentStatus.fromValue(value);
    }
}
